/********************************************************************************************************
*Purpose: Estimate core results for Neighborhood, Marriage, Mortality Children of Gautreaux Participants 
*********************************************************************************************************/ 

global fe "intakeyear yrbirth  mitrct80"
global notractfe "intakeyear yrbirth  "
global controls "female head_female headage married auto license work emp inc chicago ph i.bed"

********************************
***********  MAFARF  *********** 
********************************

global moutlist "m2007_pctblack m2007_pctwhite  m2007_povrate m2007_incrnk m2007_incrnk_black m2010_pctblack  m2010_pctwhite m2010_povrate m2010_incrnk m2010_incrnk_black m2013_pctblack m2013_pctwhite m2013_povrate m2013_incrnk m2013_incrnk_black m2016_pctblack m2016_pctwhite m2016_povrate m2016_incrnk m2016_incrnk_black m2019_pctblack m2019_pctwhite m2019_povrate m2019_incrnk m2019_incrnk_black m26_pctblack m26_pctwhite m26_povrate m26_incrnk m26_incrnk_black   m28_pctblack m28_pctwhite m28_povrate m28_incrnk m28_incrnk_black sametractage26 sametractage28 sametractparent2019"


capture frame drop marf
frame create marf str35 outcome str35 group str35 spec beta se obs piks dv1treatpiks dv1controlpiks dv0treatpiks dv0controlpiks r2

foreach gr in all girl boy {
foreach spec in base nocont notractfe meansd { 
foreach mout in $moutlist {

	if "`spec'"=="base" {
	reghdfe `mout' generalarea $controls if  estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	gen samp_`mout'_`gr'=e(sample) 	
	unique pik if e(sample)==1
	

	if "`mout'"!="sametractage26 " & "`mout'"!="sametractage28" & "`mout'"!="sametractparent2019"  {
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 
	local y0treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0 
	local y0controlpik `=-99999'
	}

	
	if "`mout'"=="sametractage26 " | "`mout'"=="sametractage28" | "`mout'"=="sametractparent2019"  {
	unique pik if e(sample)==1	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==0
	local y0controlpik `=r(sum)'
	}
	
	frame post marf ("`mout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik') (e(r2))
	}
	
	if "`spec'"=="nocont" {
	reghdfe `mout' generalarea  if  samp_`mout'_`gr'==1 & `gr'==1, absorb( $fe ) cluster(hhid)

	if "`mout'"!="sametractage26 " & "`mout'"!="sametractage28" & "`mout'"!="sametractparent2019"  {	
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 
	local y0treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0 
	local y0controlpik `=-99999'
	}

	
	if "`mout'"=="sametractage26 " | "`mout'"=="sametractage28" | "`mout'"=="sametractparent2019"  {
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==0
	local y0controlpik `=r(sum)'
	}
		
	
	frame post marf ("`mout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik') (e(r2))
			
	}
	
	if "`spec'"=="notractfe" {
	reghdfe `mout' generalarea $controls if  samp_`mout'_`gr'==1 & `gr'==1, absorb( $notractfe ) cluster(hhid)

		if "`mout'"!="sametractage26 " & "`mout'"!="sametractage28" & "`mout'"!="sametractparent2019"  {	
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 
	local y0treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0 
	local y0controlpik `=-99999'
	}

	
	if "`mout'"=="sametractage26 " | "`mout'"=="sametractage28" | "`mout'"=="sametractparent2019"  {
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `mout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `mout'==0
	local y0controlpik `=r(sum)'
	}
		

	
	frame post marf ("`mout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik') (e(r2))
			
	}
	
	if "`spec'"=="meansd" {
	sum `mout' if generalarea!=1 & `mout'!=. & `gr'==1
	local controlmean `=r(mean)'
	local controlsd `=r(sd)'
	
	unique pik if generalarea!=1 & `mout'!=. 	
	frame post marf ("`mout'") ("`gr'") ("`spec'") (`controlmean') (`controlsd') (r(sum)) (r(sum)) (-99999) (-99999) (-99999)  (-99999) (.) 
			
	}

	
	}
}
}
			

frame marf: save "${output}/kids_mafarf_results.dta", replace
frame marf: export delimited using "${output}/kids_mafarf_results.csv", replace

******************************************
****** MAFARF Homeownership Proxy  *******
******************************************

capture frame drop marfown
frame create marfown str35 outcome str35 group str35 spec beta se obs piks dv1treatpiks dv1controlpiks dv0treatpiks dv0controlpiks r2

**** MAFARF Homeownership Proxies & Number of mafids
foreach gr in older {
foreach spec in base nocont notractfe meansd { 
foreach ownvar in own20172019 avgown20172019 nummoves20172019 nummoves20152019 {

	if "`spec'"=="base" {
	reghdfe `ownvar' generalarea $controls if  estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	gen samp_`ownvar'_`gr'=e(sample) 	
	unique pik if e(sample)==1
	

	if "`ownvar'"!="own20172019"  {
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 
	local y0treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0 
	local y0controlpik `=-99999'
	}

	
	if "`ownvar'"=="own20172019" {
	unique pik if e(sample)==1	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `ownvar'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `ownvar'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `ownvar'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `ownvar'==0
	local y0controlpik `=r(sum)'
	}
	
	frame post marfown ("`ownvar'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik') (e(r2))
	}
	
	if "`spec'"=="nocont" {
	reghdfe `ownvar' generalarea  if  samp_`ownvar'_`gr'==1 & `gr'==1, absorb( $fe ) cluster(hhid)

	if "`ownvar'"!="own20172019"  {
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 
	local y0treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0 
	local y0controlpik `=-99999'
	}

	
	if "`ownvar'"=="own20172019" {
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `ownvar'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `ownvar'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `ownvar'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `ownvar'==0
	local y0controlpik `=r(sum)'
	}
		
	
	frame post marfown ("`ownvar'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik') (e(r2))
			
	}
	
	if "`spec'"=="notractfe" {
	reghdfe `ownvar' generalarea $controls if  samp_`ownvar'_`gr'==1 & `gr'==1, absorb( $notractfe ) cluster(hhid)

	if "`ownvar'"!="own20172019" {
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 
	local y0treatpik `=-99999'
	unique pik if e(sample)==1 & generalarea==0 
	local y0controlpik `=-99999'
	}

	
	if "`ownvar'"=="own20172019" {
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `ownvar'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `ownvar'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `ownvar'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `ownvar'==0
	local y0controlpik `=r(sum)'
	}
		

	
	frame post marfown ("`ownvar'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik') (e(r2))
			
	}
	
	if "`spec'"=="meansd" {
	sum `ownvar' if generalarea!=1 & `ownvar'!=. & `gr'==1
	local controlmean `=r(mean)'
	local controlsd `=r(sd)'
	
	unique pik if generalarea!=1 & `ownvar'!=. 	
	frame post marfown ("`ownvar'") ("`gr'") ("`spec'") (`controlmean') (`controlsd') (r(sum)) (r(sum)) (-99999) (-99999) (-99999)  (-99999) (.) 
			
	}

	
	}
}
}
			



frame marfown: save "${output}/kids_mafidown_results.dta", replace
frame marfown: export delimited using "${output}/kids_mafidown_results.csv", replace



			
********************************
****** MAFARF Robustness *******
********************************



capture frame drop mafarfrobust
frame create mafarfrobust str35 outcome str35 group str35 spec beta se obs piks treatpiks controlpiks

foreach mrout in  m2007_pctwhite m2007_pctblack m2007_povrate m2010_pctwhite m2010_pctblack m2010_povrate m2013_pctwhite m2013_pctblack m2013_povrate m2013_incrnk m2013_incrnk_black m2016_pctwhite m2016_pctblack m2016_povrate m2016_incrnk m2016_incrnk_black m2019_pctwhite m2019_pctblack  m2019_povrate m2019_incrnk m2019_incrnk_black m26_pctblack m26_pctwhite m26_povrate m26_incrnk m26_incrnk_black m28_pctblack m28_pctwhite m28_povrate m28_incrnk m28_incrnk_black  {
** Base
reghdfe `mrout' generalarea $controls if  estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'
	
frame post mafarfrobust  ("`mrout'") ("all") ("base") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')

	
** Low Vac Years
reghdfe `mrout' generalarea $controls if lowvac==1 & estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'

frame post mafarfrobust  ("`mrout'") ("all") ("lowvac") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')


** 1st Offers only
reghdfe `mrout' generalarea $controls if offers==1 & estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'

frame post mafarfrobust  ("`mrout'") ("all") ("1stoffer") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')


** 1st Offers only & low-vac
reghdfe `mrout' generalarea $controls if lowvac==1 & offers==1 & estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'

frame post mafarfrobust  ("`mrout'") ("all") ("1stofflowvac") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')


** Exclude <90
reghdfe `mrout' generalarea $controls if intakeyear<1990 & estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'

frame post mafarfrobust  ("`mrout'") ("all") ("exclude90") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')

** Include pre-82
reghdfe `mrout' generalarea $controls if diff==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'

frame post mafarfrobust  ("`mrout'") ("all") ("include70") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')

** Majority White
reghdfe `mrout' place_majoritywhite $controls if estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & place_majoritywhite==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & place_majoritywhite==0
	local controlpik `=r(sum)'

frame post mafarfrobust  ("`mrout'") ("all") ("majoritywhite") (_b[place_majoritywhite]) (_se[place_majoritywhite]) (e(N)) (`allpik') (`treatpik') (`controlpik')


** Suburb
reghdfe `mrout' suburb $controls if estsample==1 & generalarea!=., absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & suburb==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & suburb==0
	local controlpik `=r(sum)'

frame post mafarfrobust  ("`mrout'") ("all") ("suburb") (_b[suburb]) (_se[suburb]) (e(N)) (`allpik') (`treatpik') (`controlpik')

** Continuous measure of poverty
reghdfe `mrout' std_place_povrate $controls if estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  
	local treatpik `=-99999'
	unique pik if e(sample)==1  
	local controlpik `=-99999'

frame post mafarfrobust  ("`mrout'") ("all") ("stdpovrate") (_b[std_place_povrate]) (_se[std_place_povrate]) (e(N)) (`allpik') (`treatpik') (`controlpik')


** Continuous measure of race
reghdfe `mrout' std_place_shafam $controls if estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  
	local treatpik `=-99999'
	unique pik if e(sample)==1  
	local controlpik `=-99999'

frame post mafarfrobust  ("`mrout'") ("all") ("stdshafam") (_b[std_place_shafam]) (_se[std_place_shafam]) (e(N)) (`allpik') (`treatpik') (`controlpik')

** Continuous measure of race
reghdfe `mrout' std_place_shwhite $controls if estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  
	local treatpik `=-99999'
	unique pik if e(sample)==1  
	local controlpik `=-99999'

frame post mafarfrobust  ("`mrout'") ("all") ("stdshwhite") (_b[std_place_shwhite]) (_se[std_place_shwhite]) (e(N)) (`allpik') (`treatpik') (`controlpik')


** Horse Race: White v. Pov
reghdfe `mrout' std_place_shwhite std_place_povrate $controls if estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  
	local treatpik `=-99999'
	unique pik if e(sample)==1  
	local controlpik `=-99999'

frame post mafarfrobust  ("`mrout'") ("all") ("HRwhite_v_pov_betawhite") (_b[std_place_shwhite]) (_se[std_place_shwhite]) (e(N)) (`allpik') (`treatpik') (`controlpik')
frame post mafarfrobust  ("`mrout'") ("all") ("HRwhite_v_pov_betapov") (_b[std_place_povrate]) (_se[std_place_povrate]) (e(N)) (`allpik') (`treatpik') (`controlpik')

** Horse Race:  Black v. pov
reghdfe `mrout' std_place_shafam std_place_povrate $controls if estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  
	local treatpik `=-99999'
	unique pik if e(sample)==1  
	local controlpik `=-99999'

frame post mafarfrobust  ("`mrout'") ("all") ("HRblack_v_pov_betablack") (_b[std_place_shafam]) (_se[std_place_shafam]) (e(N)) (`allpik') (`treatpik') (`controlpik')
frame post mafarfrobust  ("`mrout'") ("all") ("HRblack_v_pov_betapov") (_b[std_place_povrate]) (_se[std_place_povrate]) (e(N)) (`allpik') (`treatpik') (`controlpik')





}


foreach a26out in m26_pctblack m26_pctwhite m26_povrate m26_incrnk m26_incrnk_black {

** Age 26 not at placement tract 
reghdfe `a26out' generalarea treatsametractage26 $controls if  estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'
	
frame post mafarfrobust  ("`a26out'") ("all") ("treatsametractage26") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')
}

foreach a28out in m28_pctblack m28_pctwhite m28_povrate m28_incrnk m28_incrnk_black {

** Age 28 not at placement tract 
reghdfe `a28out' generalarea treatsametractage28 $controls if  estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'
	
frame post mafarfrobust  ("`a28out'") ("all") ("treatsametractage28") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')
}

foreach vmout in m2019_pctwhite m2019_pctblack  m2019_povrate m2019_incrnk m2019_incrnk_black {
reghdfe `vmout' generalarea treat_sameparent2019 $controls if  estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0
	local controlpik `=r(sum)'
	
frame post mafarfrobust  ("`vmout'") ("all") ("parenttract2019") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`treatpik') (`controlpik')
}



frame mafarfrobust: save "${output}/mafarf_robustness_results.dta", replace
frame mafarfrobust: export delimited using "${output}/mafarf_robustness_results.csv", replace



*********************************
********* Census Outcomes *******
*********************************

*** neighborhood, marriage, ownership

global cenout "married_2010 married_white owner_2010 refheadsps incar_2010 c2010_majoritywhite"


capture frame drop cen10
frame create cen10 str35 outcome str35 group str35 spec beta se obs piks dv1treatpiks dv1controlpiks dv0treatpiks dv0controlpiks

foreach gr in all girl boy age35 {
foreach spec in base nocont notractfe meansd { 
foreach cout in $cenout {

	if "`spec'"=="base" {
	reghdfe `cout' generalarea $controls if  estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	gen samp_`cout'_`gr'=e(sample) 	
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post cen10 ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	}
	
	if "`spec'"=="nocont" {
	reghdfe `cout' generalarea  if  samp_`cout'_`gr'==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post cen10 ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
			
	}
	
	if "`spec'"=="notractfe" {
	reghdfe `cout' generalarea $controls if  samp_`cout'_`gr'==1 & `gr'==1, absorb( $notractfe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `cout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `cout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post cen10 ("`cout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
			
	}
	
	if "`spec'"=="meansd" {
	sum `cout' if generalarea!=1 & `cout'!=. & `gr'==1
	local controlmean `=r(mean)'
	local controlsd `=r(sd)'
	
	unique pik if generalarea!=1 & `cout'!=. 	
	frame post cen10 ("`cout'") ("`gr'") ("`spec'") (`controlmean') (`controlsd') (r(sum)) (r(sum)) (r(sum)) (r(sum)) (r(sum))  (r(sum)) 
			
	}

	
	}
}
}
frame cen10: save "${output}/kids_cen10_results.dta", replace
frame cen10: export delimited using "${output}/kids_cen10_results.csv", replace


*********************************
******* Census Robustness *******
*********************************

global cenout "married_2010 married_white owner_2010 incar_2010 c2010_majoritywhite"


capture frame drop cenrobust
frame create cenrobust str35 outcome str35 group str35 spec beta se obs piks dv1treatpiks dv1controlpiks dv0treatpiks dv0controlpiks


foreach gr in all age35 boy girl {
foreach crout in $cenout {

	* Base
	reghdfe `crout' generalarea $controls if  estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post cenrobust ("`crout'") ("`gr'") ("base") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')

	* lowvac
	reghdfe `crout' generalarea $controls if  lowvac==1 & estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post cenrobust ("`crout'") ("`gr'") ("lowvac") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')


	* 1st Offer only
	reghdfe `crout' generalarea $controls if  offers==1 & estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post cenrobust ("`crout'") ("`gr'") ("1stoffer") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')


	
	* 1st Offer only
	reghdfe `crout' generalarea $controls if lowvac==1 & offers==1 & estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post cenrobust ("`crout'") ("`gr'") ("1stofflowvac") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	
	
	* Exclude 90s
	reghdfe `crout' generalarea $controls if intakeyear<1990 & estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post cenrobust ("`crout'") ("`gr'") ("exclude90") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
			
	** Include pre-82
	reghdfe `crout' generalarea $controls if diff==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==0
	local y0controlpik `=r(sum)'
	

frame post cenrobust  ("`crout'") ("`gr'")  ("include70") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')

	* HHFE 
	reghdfe `crout' ageTreatment ageatintake if estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid yrbirth)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post cenrobust ("`crout'") ("`gr'") ("hhfe_continuous") (_b[ageTreatment]) (_se[ageTreatment]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	
	* HHFE 
	reghdfe `crout' ageTreatment if estsample==1 & `gr'==1, absorb( hhid female yrbirth chicago ) cluster(hhid yrbirth)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `crout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `crout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post cenrobust ("`crout'") ("`gr'") ("hhfe_continuous") (_b[ageTreatment]) (_se[ageTreatment]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	
		
	* HHFE - binary exposure
	reghdfe `crout' youngerTreat younger if estsample==1 & `gr'==1, absorb( hhid female yrbirth chicago ) cluster(hhid yrbirth)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & youngerTreat==1 & `crout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & youngerTreat==0 & `crout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & youngerTreat==1 & `crout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & youngerTreat==0 & `crout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post cenrobust ("`crout'") ("`gr'") ("hhfe_binary") (_b[youngerTreat]) (_se[youngerTreat]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	

** Continuous measure of race
reghdfe `crout' std_place_shafam $controls if estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  & `crout'==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1  & `crout'!=1
	local controlpik `=r(sum)'

frame post cenrobust  ("`crout'") ("all") ("stdshafam") (_b[std_place_shafam]) (_se[std_place_shafam]) (e(N)) (`allpik') (`treatpik') (`controlpik') (`treatpik') (`controlpik')

** Continuous measure of race
reghdfe `crout' std_place_shwhite $controls if estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  & `crout'==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1  & `crout'!=1
	local controlpik `=r(sum)'

frame post cenrobust  ("`crout'") ("all") ("stdshwhite") (_b[std_place_shwhite]) (_se[std_place_shwhite]) (e(N)) (`allpik') (`treatpik') (`controlpik') (`treatpik') (`controlpik')
 

** Horse Race: White v. Pov
reghdfe `crout' std_place_shwhite std_place_povrate $controls if estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & `crout'==1  
	local treatpik `=r(sum)'
	unique pik if e(sample)==1 & `crout'!=1 
	local controlpik `=r(sum)'

frame post cenrobust  ("`crout'") ("all") ("HRwhite_v_pov_betawhite") (_b[std_place_shwhite]) (_se[std_place_shwhite]) (e(N)) (`allpik') (`treatpik') (`controlpik') (`treatpik') (`controlpik')
frame post cenrobust  ("`crout'") ("all") ("HRwhite_v_pov_betapov") (_b[std_place_povrate]) (_se[std_place_povrate]) (e(N)) (`allpik') (`treatpik') (`controlpik') (`treatpik') (`controlpik')

** Horse Race:  Black v. pov
reghdfe `crout' std_place_shafam std_place_povrate $controls if estsample==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  & `crout'==1
	local treatpik `=r(sum)'
	unique pik if e(sample)==1  & `crout'!=1
	local controlpik `=r(sum)'

frame post cenrobust  ("`crout'") ("all") ("HRblack_v_pov_betablack") (_b[std_place_shafam]) (_se[std_place_shafam]) (e(N)) (`allpik') (`treatpik') (`controlpik') (`treatpik') (`controlpik')
frame post cenrobust  ("`crout'") ("all") ("HRblack_v_pov_betapov") (_b[std_place_povrate]) (_se[std_place_povrate]) (e(N)) (`allpik') (`treatpik') (`controlpik') (`treatpik') (`controlpik')
	
	
	
}
}
frame cenrobust: save "${output}/kids_cenrobust_results.dta", replace
frame cenrobust: export delimited using "${output}/kids_cenrobust_results.csv", replace

********************************
***** Census Neighborhood ****** 
********************************

global cenneigh "c2000_shwhite c2000_shblack c2000_povrate c2010_shwhite c2010_shblack c2010_povrate"


capture frame drop cenneigh
frame create cenneigh str35 outcome str35 group str35 spec beta se obs piks treatpiks controlpiks 

foreach gr in all girl boy {
foreach spec in base nocont notractfe meansd { 
foreach cnout in $cenneigh {

	if "`spec'"=="base" {
	reghdfe `cnout' generalarea $controls if  estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	gen samp_`cnout'_`gr'=e(sample) 	
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1  
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0  
	local y1controlpik `=r(sum)'
	
	
	frame post cenneigh ("`cnout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik')  
	}
	
	if "`spec'"=="nocont" {
	reghdfe `cnout' generalarea  if  samp_`cnout'_`gr'==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1

	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1  
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0  
	local y1controlpik `=r(sum)'
		
	frame post cenneigh ("`cnout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik')  
			
	}
	
	if "`spec'"=="notractfe" {
	reghdfe `cnout' generalarea $controls if  samp_`cnout'_`gr'==1 & `gr'==1, absorb( $notractfe ) cluster(hhid)
	unique pik if e(sample)==1

	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1  
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0  
	local y1controlpik `=r(sum)'
	
	
	frame post cenneigh ("`cnout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik')  
			
	}
	
	if "`spec'"=="meansd" {
	sum `cnout' if generalarea!=1 & `cnout'!=. & `gr'==1
	local controlmean `=r(mean)'
	local controlsd `=r(sd)'
	
	unique pik if generalarea!=1 & `cnout'!=. 	
	frame post cenneigh ("`cnout'") ("`gr'") ("`spec'") (`controlmean') (`controlsd') (r(sum)) (r(sum)) (r(sum)) (r(sum))  
			
	}

	
	}
}
}
frame cenneigh: save "${output}/kids_cen_neighborhood_results.dta", replace
frame cenneigh: export delimited using "${output}/kids_cen_neighborhood.csv", replace





********************************
*********** Mortality ********** 
********************************

capture frame drop numid
frame create numid str35 outcome str35 group str35 spec beta se obs piks dv1treatpiks dv1controlpiks dv0treatpiks dv0controlpiks

foreach gr in all girl boy {
foreach spec in base nocont notractfe meansd { 
foreach vout in died {

	if "`spec'"=="base" {
	reghdfe `vout' generalarea $controls if  estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	gen samp_`vout'_`gr'=e(sample) 	
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `vout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `vout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `vout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `vout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post numid ("`vout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	}
	
	if "`spec'"=="nocont" {
	reghdfe `vout' generalarea  if  samp_`vout'_`gr'==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `vout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `vout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `vout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `vout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post numid ("`vout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
			
	}
	
	if "`spec'"=="notractfe" {
	reghdfe `vout' generalarea $controls if  samp_`vout'_`gr'==1 & `gr'==1, absorb( $notractfe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `vout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `vout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `vout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `vout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post numid ("`vout'") ("`gr'") ("`spec'") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
			
	}
	
	if "`spec'"=="meansd" {
	sum `vout' if generalarea!=1 & `vout'!=. & `gr'==1
	local controlmean `=r(mean)'
	local controlsd `=r(sd)'
	
	unique pik if generalarea!=1 & `vout'!=. 	
	frame post numid ("`vout'") ("`gr'") ("`spec'") (`controlmean') (`controlsd') (r(sum)) (r(sum)) (r(sum)) (r(sum)) (r(sum))  (r(sum)) 
			
	}

	
	}
}
}
frame numid: save "${output}/kids_mortality_results.dta", replace
frame numid: export delimited using "${output}/kids_mortality_results.csv", replace

********************************
***** Numident Robustness ****** 
********************************
capture frame drop numrobust
frame create numrobust str35 outcome str35 group str35 spec beta se obs piks dv1treatpiks dv1controlpiks dv0treatpiks dv0controlpiks


foreach gr in all girl boy {
foreach nout in died {

	* Base
	reghdfe `nout' generalarea $controls if  estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post numrobust ("`nout'") ("`gr'") ("base") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')

	* lowvac
	reghdfe `nout' generalarea $controls if  lowvac==1 & estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post numrobust ("`nout'") ("`gr'") ("lowvac") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')


	* 1st Offer only
	reghdfe `nout' generalarea $controls if  offers==1 & estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post numrobust ("`nout'") ("`gr'") ("1stoffer") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')


	
	* 1st Offer only
	reghdfe `nout' generalarea $controls if lowvac==1 & offers==1 & estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post numrobust ("`nout'") ("`gr'") ("1stofflowvac") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	
	
	* Exclude 90s
	reghdfe `nout' generalarea $controls if intakeyear<1990 & estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post numrobust ("`nout'") ("`gr'") ("exclude90") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
			
	** Include pre-82
	reghdfe `nout' generalarea $controls if diff==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==0
	local y0controlpik `=r(sum)'
	

frame post numrobust  ("`nout'") ("`gr'")  ("include70") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')

	* HHFE 
	reghdfe `nout' ageTreatment ageatintake if estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid yrbirth)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post numrobust ("`nout'") ("`gr'") ("hhfe_continuous") (_b[ageTreatment]) (_se[ageTreatment]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	
	* HHFE 
	reghdfe `nout' ageTreatment if estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid yrbirth)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `nout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `nout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post numrobust ("`nout'") ("`gr'") ("hhfe_continuous") (_b[ageTreatment]) (_se[ageTreatment]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	
		
	* HHFE - binary exposure
	reghdfe `nout' youngerTreat younger if estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid yrbirth)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & youngerTreat==1 & `nout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & youngerTreat==0 & `nout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & youngerTreat==1 & `nout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & youngerTreat==0 & `nout'==0
	local y0controlpik `=r(sum)'
	
	
	frame post numrobust ("`nout'") ("`gr'") ("hhfe_binary") (_b[youngerTreat]) (_se[youngerTreat]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	
	


** Continuous measure of race
reghdfe `nout' std_place_shafam $controls if estsample==1 & `gr'==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  
	local treatpik `=r(sum)'
	unique pik if e(sample)==1  
	local controlpik `=r(sum)'

frame post numrobust  ("`nout'") ("`gr'") ("stdshafam") (_b[std_place_shafam]) (_se[std_place_shafam]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	

** Continuous measure of race
reghdfe `nout' std_place_shwhite $controls if estsample==1 & `gr'==1 , absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  
	local treatpik `=r(sum)'
	unique pik if e(sample)==1  
	local controlpik `=r(sum)'

frame post numrobust  ("`nout'") ("`gr'") ("stdshwhite") (_b[std_place_shwhite]) (_se[std_place_shwhite]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	


** Horse Race: White v. Pov
reghdfe `nout' std_place_shwhite std_place_povrate $controls if estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  
	local treatpik `=r(sum)'
	unique pik if e(sample)==1  
	local controlpik `=r(sum)'

frame post numrobust  ("`nout'") ("`gr'") ("HRwhite_v_pov_betawhite") (_b[std_place_shwhite]) (_se[std_place_shwhite]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	
frame post numrobust  ("`nout'") ("`gr'") ("HRwhite_v_pov_betapov") (_b[std_place_povrate]) (_se[std_place_povrate]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	

** Horse Race:  Black v. pov
reghdfe `nout' std_place_shafam std_place_povrate $controls if estsample==1 & `gr'==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	local allpik `=r(sum)'
	unique pik if e(sample)==1  
	local treatpik `=r(sum)'
	unique pik if e(sample)==1  
	local controlpik `=r(sum)'

frame post numrobust  ("`nout'") ("`gr'") ("HRblack_v_pov_betablack") (_b[std_place_shafam]) (_se[std_place_shafam]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
	
frame post numrobust  ("`nout'") ("`gr'") ("HRblack_v_pov_betapov") (_b[std_place_povrate]) (_se[std_place_povrate]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')
		
	
	
}
}
frame numrobust: save "${output}/kids_numrobust_results.dta", replace
frame numrobust: export delimited using "${output}/kids_numrobust_results.csv", replace


********************************
*** Attrition / Non Response ***
********************************
gen has2007tract=(tract_maf2007!="")
gen has2010tract=(tract_maf2010!="")
gen has2013tract=(tract_maf2013!="")
gen has2016tract=(tract_maf2016!="")
gen has2019tract=(tract_maf2019!="")
gen hasage26tract=(tract_maf26!="") 
gen hasage28tract=(tract_maf28!="") 


capture frame drop attritnonresp
frame create attritnonresp str35 outcome str35 group  str35 spec beta se N piks dv1treatpiks dv1controlpiks dv0treatpiks dv0controlpiks

foreach aout in hascensus2010 hasage26tract hasage28tract has2007tract has2010tract has2013tract has2016tract has2019tract {


	* Base
	reghdfe `aout' generalarea $controls if  estsample==1, absorb( $fe ) cluster(hhid)
	unique pik if e(sample)==1
	
	local allpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `aout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `aout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `aout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `aout'==0
	local y0controlpik `=r(sum)'
	
	frame post attritnonresp  ("`aout'") ("kids") ("base") (_b[generalarea]) (_se[generalarea]) (e(N)) (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')

	sum `aout' if e(sample)==1 & generalarea==0
	local cmean `=r(mean)'
	local csd `=r(sd)'
	local N `=r(N)'
	
	local allpik `=r(N)'
	unique pik if e(sample)==1 & generalarea==1 & `aout'==1
	local y1treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `aout'==1
	local y1controlpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==1 & `aout'==0
	local y0treatpik `=r(sum)'
	unique pik if e(sample)==1 & generalarea==0 & `aout'==0
	local y0controlpik `=r(sum)'

	frame post attritnonresp  ("`aout'") ("kids") ("meansd") (`cmean') (`csd') (`N') (`allpik') (`y1treatpik') (`y1controlpik') (`y0treatpik') (`y0controlpik')

	
}

capture frame drop blankframe
frame create blankframe
frame change blankframe

do "/projects/programs/Gautreaux/analysis/03b_kids_regressions_haspik.do"

frame change default

frame attritnonresp: save "${output}/attritnonresp_results.dta", replace
frame attritnonresp: export delimited using "${output}/attritnonresp_results.csv", replace

*** has PIK regression x
*** has census 2010 response x
*** 2000 Census "Endogenous Moves"
*** Add balance X
*** Census 2010 Robustness X
*** Census MAFARF Robustness X

